import router from "./index.js";
import store from "@/store";
import { Message } from 'element-ui';
var whiteList = ['/login'];
const typeList = ['/account/addaccount', '/account/listaccount']
console.log((whiteList));
router.beforeEach((to, from, next) => {
    console.log("路由守卫运行了", to, from, next);
    console.log(store.getters.token);
    if (store.getters.token) {//已经登录成功了
        if (to.path == '/login') {
            //跳到首页
            next('/home/dashboard');
        } else if (typeList.indexOf(to.path) !== -1) {//判断是不是超级管理员才能访问的页面
            if (store.getters.type == "1") {//判断登录的用户是不是超级管理员
                next();
            } else {//非超级
                Message({ message: "您没有权限访问该页面，请使用超级管理员身份登录", type: "warning" });
                //退出
                store.dispatch('LogoutAction');
                //跳转
                next('/login');
            }
        } else {
            //放行
            next();
        }
    } else {//没登录 
        if (whiteList.indexOf(to.path) !== -1) {//在白名单
            next();
        } else {
            next('/login');
        }
    }
})